package com.zjh.photoshopstudy.Utils;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.text.TextPaint;
import android.text.style.ClickableSpan;
import android.view.View;

public class LinkClick extends ClickableSpan {
    Context context;
    String mUrl;

    public LinkClick(Context context, String Url) {
        this.context = context;
        this.mUrl = Url;
    }

    @Override
    public void updateDrawState(TextPaint ds) {
        ds.setUnderlineText(false);
    }

    @Override
    public void onClick(@NonNull View view) {
        if (!(mUrl.startsWith("http://") || mUrl.startsWith("https://"))) {
            mUrl = "http://" + mUrl;
        }
        Intent it = new Intent(Intent.ACTION_VIEW);
        it.setData(Uri.parse(mUrl));
        context.startActivity(it);
    }
}